layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 同城搬家车类型管理
     */
    var FlowServiceType = {
        tableId: "flowServiceTypeTable"
    };

    /**
     * 初始化表格的列
     */
    FlowServiceType.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'commissionId', hide: true, title: 'ID'},
            {field: 'orderId', sort: true, title: '工单Id'},
            // {field: 'typeUrl', sort: true, title: '车辆图片',templet:function (row) {
            //         return row.typeUrl ? "<img src='"+row.typeUrl+"' />" : "无";
            // }},
            // {field: 'type', sort: true, title: '类型',templet:function (row) {
            //         return row.type == 0 ? '全包' : '计算物品费';
            // }},
            {field: 'oneDrawPrice', sort: true, title: '单笔佣金'},
            {field: 'createTime', sort: true, title: '创建时间'},
            {field: 'applyDrawPrice', sort: true, title: '提现申请金额'},
            {field: 'allPrice', sort: true, title: '总佣金'},
            {field: 'drawPrice', sort: true, title: '已提现金额'},
            {field: 'canDrawPrice', sort: true, title: '可提现金额'},
            {field: 'drawSign', hide: true, title: ''},
            {field: 'onlySign', hide: true, title: ''},
            {align: 'center', toolbar: '#tableBar', title: '操作',width:200}
        ]];
    };

    /**
     * 点击查询按钮
     */
    FlowServiceType.search = function () {
        var queryData = {};


        table.reload(FlowServiceType.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

     /**
      * 点击编辑
      *
      * @param data 点击按钮时候的行数据
      */
      FlowServiceType.openShowDlg = function (data) {
          func.open({
              title: '订单详情',
              content: Feng.ctxPath + '/flowOrder/edit?orderId=' + data.orderId,
              tableId: FlowServiceType.tableId
          });
      };


    // FlowServiceType.openSignDlg = function (data) {
    //     func.open({
    //         title: '区间费用配置',
    //         content: Feng.ctxPath + '/flowServiceAreaPrice?serviceTypeId=' + data.serviceTypeId+"&storeCityId="+Feng.getUrlParam("storeCityId"),
    //         tableId: FlowServiceType.tableId
    //     });
    // };

    FlowServiceType.openSignDlg = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/flowWxMember/transfer", function (data) {
                if(data.code == 200){
                    Feng.success("操作成功!");
                    table.reload(FlowServiceType.tableId);
                }else {
                    Feng.error(data.message);
                }

            }, function (data) {
                Feng.error("操作失败!" + data.responseJSON.message + "!");
            });
            ajax.set("applyDrawPrice", data.applyDrawPrice);
            ajax.set("userId", data.userId);
            ajax.set("commissionId", data.commissionId);
            ajax.start();
        };
        Feng.confirm("审核通过?", operation);
    };

    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    // FlowServiceType.openCarEditDlg = function (data) {
    //     func.open({
    //         title: '汽车费用配置',
    //         content: Feng.ctxPath + '/flowStoreCity/flowServiceTypePriceEdit?serviceTypeId=' + data.serviceTypeId+"&storeCityId="+Feng.getUrlParam("storeCityId"),
    //         tableId: FlowServiceType.tableId
    //     });
    // };

    // FlowServiceType.openElevatorDlg = function(data){
    //     func.open({
    //         title: '楼层计费配置',
    //         content: Feng.ctxPath + '/flowStoreCity/flowElevatorPrice?storeCityId=' + Feng.getUrlParam("storeCityId")+'&serviceTypeId='+data.serviceTypeId,
    //         tableId: FlowServiceType.tableId
    //     });
    // };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + FlowServiceType.tableId,
        url: Feng.ctxPath + '/flowCommissionManagement/list?userId='+Feng.getUrlParam("userId"),
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: FlowServiceType.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        FlowServiceType.search();
    });

    // 工具条点击事件
    table.on('tool(' + FlowServiceType.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'show') {
            FlowServiceType.openShowDlg(data);
        }else if(layEvent === 'sign'){
            FlowServiceType.openSignDlg(data);
        }
        // else if (layEvent === 'elevatorConfig') {
        //     FlowServiceType.openElevatorDlg(data);
        // }else if (layEvent === 'area') {
        //     FlowServiceType.openAreaDlg(data);
        // }
    });
});
